/*
author: Joanna
time:   2012.04.26
version v1.0
*/

$.fn.bgIframe = $.fn.bgiframe = function(s) {
// This is only for IE6
if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
	s = $.extend({
		top     : 'auto', // auto == .currentStyle.borderTopWidth
		left    : 'auto', // auto == .currentStyle.borderLeftWidth
		width   : 'auto', // auto == offsetWidth
		height  : 'auto', // auto == offsetHeight
		opacity : true,
		src     : 'javascript:false;'
	}, s || {});
	var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
				   'style="display:block;position:absolute;z-index:-1;'+
					   (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					   'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					   'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					   'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					   'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
				'"/>';
	return this.each(function() {
		if ( $('> iframe.bgiframe', this).length == 0 )
			this.insertBefore( document.createElement(html), this.firstChild );
	});
}
return this;
};

;(function($){
	$.fn.popShadow = function (o){
		var settings = {
			elems          :  '',
			hasShadow      :  true,
			closeElement   :  ".close",
			zShadowIndex         : '9',
			zElemsIndex         : '9998',
			backgroundColor: '#000',
			opacity        : '0.6',
			event          : 'click',//mouseover, null
			isIE6          : $.browser.msie&&parseFloat($.browser.version)<7,
			before         : function(){},
			after          : function(){},
			isExist        : function (elem){
								if(typeof elem !== 'undefined' && typeof elem !== null) {
										return true;
								}else{
									return false;	
								}
							  }
			
		};
		o = $.extend(settings, o);
		return this.each(function(){
			var _this = $(this);
			/*** addOverlay ***/
			if (o.hasShadow == true){
					var addOverlay = function(cl, op){
					removeOverlay();
					var	overlayCss = {
						position       : 'fixed',
						zIndex         : o.zShadowIndex,
						top            : '0px',
						left           : '0px',
						height         : '100%',
						width          : '100%',
						backgroundColor: o.backgroundColor,
						//filter         : 'alpha(opacity=60)',
						opacity        : o.opacity
					},
					overlayCssIe6 = { 
								position : 'absolute',
								height   : $(document).height()
					};
					var overlay = $('<div id="Overlay" class="OverlayBG" />');	
					/*if(O.isExist(cl))	{	
							overlayCss.backgroundColor = cl;
					};*/
					$('body').append(overlay.css(overlayCss));	
					if(o.isIE6)	{
							overlay.css(overlayCssIe6);
							$(overlay).bgIframe(); //ie6 select bug
					};	
					if(o.isExist(op)){		
					   $('#Overlay').animate({opacity: op},0);	
					}
				 };
				var removeOverlay = function(){
					if(o.isExist($('#Overlay')))		
						$('#Overlay').remove();
				};
			}
			var showShadow = function(){
			    o.before();	
				if (o.hasShadow == true)	{
					addOverlay(o.backgroundColor, o.opacity);
				};
				if (o.isIE6){
					var high = ($(window).height()-$(o.elems).height())/2 + $(window).scrollTop();
					var width = ($(window).width()-$(o.elems).width())/2+$(window).scrollLeft();
					$(o.elems).css("position","absolute")
						   .css("top", high)
						   .css("left",width)
						   .css("z-index",o.zElemsIndex)
						   .fadeIn();
					$(window).scroll( function() { 
							$(o.elems).css("top",($(window).height()-$(o.elems).height())/2 + $(window).scrollTop())
								   .css("left",($(window).width()-$(o.elems).width())/2+$(window).scrollLeft())
						});
					$(o.elems).bgIframe(); //ie6 select bug
				}
				else {
					$(o.elems).css("position","fixed")
						  .css("top",($(window).height()-$(o.elems).height())/2)
						  .css("left",($(window).width()-$(o.elems).width())/2)
						  .css("z-index",o.zElemsIndex)
						  .fadeIn();
				};
				o.after();
				return false;
			}
			if(o.event){
				_this.bind(o.event, showShadow);
			}
			else{
				showShadow();
			}
			
			$(o.closeElement).click(function(){
				if(o.hasShadow == true) {removeOverlay();}
				$(o.elems).fadeOut();
				return false;	
			});
		})
		
	}
})(jQuery);